// es6 polyfill
import 'core-js/fn/array/find-index';

import oolongSpin from './spin';
import oolongBreadcrumb from './breadcrumb';
import oolongButton from './button';
import oolongPanel from './panel';
import oolongCheckbox from './checkbox';
import oolongColorBox from './color-box';
import oolongDatePicker from './date-picker';
import oolongDropdown from './dropdown';
import oolongForm from './form';
import oolongIcon from './icon';
import oolongInput from './input';
import oolongInputNumber from './input-number';
import oolongLoadingBar from './loading-bar';
import oolongMessage from './message';
import oolongDialog from './dialog';
import oolongMenu from './menu';
import oolongNotice from './notice';
import oolongPage from './page';
import oolongPoptip from './poptip';
import oolongRadio from './radio';
import oolongSlider from './slider';
import oolongSwitch from './switch';
import oolongTable from './table';
import oolongTag from './tag';
import oolongTabs from "./tabs"
import oolongCollapse from "./collapse"

import oolongTimePicker from './time-picker';
import oolongTooltip from './tooltip';
import { oolongSelect, oolongOption, oolongOptionGroup } from './select';
import locale from '../locale';

const oolongComponents = {
  oolongCollapse,
  oolongCollapsePanel: oolongCollapse.oolongCollapsePanel,
  oolongTabs,
  oolongTabPane:oolongTabs.oolongTabPane,
  oolongBreadcrumb,
  oolongBreadcrumbItem: oolongBreadcrumb.Item,
  oolongButton,
  oolongButtonGroup: oolongButton.Group,
  oolongPanel,
  oolongCheckbox,
  oolongColorBox,
  oolongDatePicker,
  oolongCheckboxGroup: oolongCheckbox.Group,
  oolongDropdown,
  oolongDropdownItem: oolongDropdown.Item,
  oolongDropdownMenu: oolongDropdown.Menu,
  oolongForm,
  oolongFormItem:oolongForm.Item,
  oolongIcon,
  oolongInput,
  oolongInputNumber,
  oolongLoadingBar,
  oolongMessage,
  oolongDialog,
  oolongMenu,
  oolongMenuGroup: oolongMenu.Group,
  oolongMenuItem: oolongMenu.Item,
  oolongSubmenu: oolongMenu.Sub,
  oolongNotice,
  oolongPage,
  oolongPoptip,
  oolongRadio,
  oolongRadioGroup: oolongRadio.Group,
  oolongSelect,
  oolongOption:oolongOption,
  oolongOptionGroup:oolongOptionGroup,
  oolongSlider,
  oolongSwitch,
  oolongTable,
  oolongTag,
  oolongTimePicker,
  oolongTooltip,
  oolongSpin
};

const install = function (Vue, opts = {}) {
  locale.use(opts.locale);
  locale.i18n(opts.i18n);

  Object.keys(oolongComponents).forEach((key) => {
    Vue.component(key, oolongComponents[key]);
  });

  Vue.prototype.$Loading = oolongLoadingBar;
  Vue.prototype.$Message = oolongMessage;
  Vue.prototype.$Dialog = oolongDialog;
  Vue.prototype.$Notice = oolongNotice;
};

// auto install
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue);
}

export default Object.assign(oolongComponents, {install});   // eslint-disable-line no-undef
